package cn.framework.dao.impl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.persister.entity.SingleTableEntityPersister;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.framework.dao.BaseHibernateDao;
import cn.framework.dao.BaseProxyHibernateDao;
import cn.framework.dao.model.OrderBy;
import cn.framework.dao.util.DaoUtil;
@Repository
@SuppressWarnings("unchecked")
public class BaseProxyHibernateDaoImpl<T> extends BaseHibernateDaoImpl<T> implements BaseHibernateDao,BaseProxyHibernateDao {

	public boolean delete(Object domain, HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return delete(domain);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return false;
	}

	public boolean delete(List domainList, HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return delete(domainList);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return false;
	}

	public boolean deleteByKey(Serializable id,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return deleteByKey(id);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return false;
	}

	public List findAll(HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findAll(int firstResult, int size,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findAll(firstResult,size);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findByExample(Object value, HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findByExample(value);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findByExample(Object value, int firstResult, int maxResults,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findByExample(value,firstResult,maxResults);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public Object findById(Serializable id, HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findByProperty(String propertyName, Object value,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findByProperty(propertyName,value);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findByProperty(String propertyName, Object value,
			Integer firstResult, Integer size,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findByProperty(propertyName,value,firstResult,size);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findByProperty(String[] propertyNames, Object[] values,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findByProperty(propertyNames,values);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findByProperty(String[] propertyNames, Object[] values,
			Integer firstResult, Integer size,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findByProperty(propertyNames,values,firstResult,size);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public Object findByUnique(String propertyName, Object value,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findByUnique(propertyName,value);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public Object findByUnique(String[] propertyNames, Object[] values,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findByUnique(propertyNames,values);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findIn(String propertyName, Object[] value,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findIn(propertyName,value);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findOrByProperty(String[] propertyNames, Object[] values,
			Integer firstResult, Integer size,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findOrByProperty(propertyNames,values,firstResult,size);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findOrLikeByProperty(String[] propertyNames, Object[] values,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findOrLikeByProperty(propertyNames,values);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List findOrLikeByProperty(String[] propertyNames, Object[] values,
			Integer firstResult, Integer size,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return findOrLikeByProperty(propertyNames,values,firstResult,size);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List fuzzyFindByProperty(String propertyName, Object value,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return fuzzyFindByProperty(propertyName,value);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List fuzzyFindByProperty(String propertyName, Object value,
			Integer firstResult, Integer size,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return fuzzyFindByProperty(propertyName,value,firstResult,size);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List fuzzyFindByProperty(String[] propertyNames, Object[] values,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return fuzzyFindByProperty(propertyNames,values);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public List fuzzyFindByProperty(String[] propertyNames, Object[] values,
			Integer firstResult, Integer size,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return fuzzyFindByProperty(propertyNames,values,firstResult,size);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public int getCount(HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return getCount();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return 0;
	}

	public int getCount(String propertyName, Object value,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return getCount(propertyName,value);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return 0;
	}

	public int getCount(String[] propertyNames, Object[] values,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return getCount(propertyNames,values);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return 0;
	}

	public Object save(Object domain, HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return save(domain);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public Object saveOrUpdate(Object domain,
			HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return saveOrUpdate(domain);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}

	public Object update(Object domain, HibernateTemplate hibernateTemplate) {
		try {
			super.setHibernateTemplate(hibernateTemplate);
			return update(domain);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			rebackDefaultDB();
		}
		return null;
	}
	
	
}
